package diet

import (
	"github.com/bgmp/config"
	"github.com/bgmp/handler"
	"github.com/bgmp/model"
	"github.com/gin-gonic/gin"
)

func (b Base) SetDetail(c *gin.Context, req *NutritionDetailRequest) *NutritionDetailResponse {
	diet := model.Diet{}
	diet.ID = req.DietId
	err := diet.Get(config.DB)
	if err != nil {
		handler.Errorf(c, "diet 不存在")
		return nil
	}
	diet.Comment = req.Comment
	diet.CreatedAt = req.EatAt.Time
	diet.SetType(req.Type)

	err = diet.Save(config.DB)

	if err != nil {
		return &NutritionDetailResponse{
			Msg: "fail",
		}
	}

	return &NutritionDetailResponse{
		Msg: "success",
	}
}

type NutritionDetailRequest struct {
	DietId  uint       `json:"dietId"`
	Comment string     `json:"comment"`
	EatAt   model.Time `json:"eatAt"`
	Type    string     `json:"type"`
}

type NutritionDetailResponse struct {
	Msg string `json:"msg"`
}
